package com.itheima.controller;

import com.itheima.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
    //响应页面、跳转页面
    @RequestMapping("/index")
    public String toJumpPage(){
        System.out.println("跳转页面");
        return "index.jsp";
    }
    //  响应文本数据
    @RequestMapping("/toText")
    @ResponseBody
    public String toText(){
        System.out.println("返回纯文本数据");
        return "response text";
    }
    //响应pojo
    @RequestMapping("/toJsonPojo")
    @ResponseBody
    public User toJosnPojo(){
        System.out.println("返回json对象");
        User user = new User();
        user.setName("张三");
        user.setAge(19);
        return user;
    }

    //响应pojo集合对象
    @RequestMapping("/toJsonList")
    @ResponseBody
    public List<User> tojsonList(){
        System.out.println("返回json对象数据");
        User user = new User();
        user.setName("张三");
        user.setAge(19);
        List<User> list = new ArrayList<User>();
        list.add(user);
        return list;

    }
}
